
<html lang="en">
        <head>
            <title>乐摩吧-巡场签到</title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
            
            <!-- <link href="css/mui.min.css" rel="stylesheet" /> -->
            <link href="css/reset.css" rel="stylesheet" />
            <link href="css/index.css" rel="stylesheet" />
            <link href="css/weui.min.css" rel="stylesheet" />
        </head>
        <body ontouchstart>
            <div class="viewport">
                <div class="weui-tab" id="tab">
                    <div class="header">
                        <h2>巡场签到</h2>
                        <p>用于巡场人员到达所负责网点现场后签到使用</p>
                    </div>
                    <div class="content">
                        <div class="c-c">
                            <div>
                                <p class="areaname">区域名称：</p>
                                <select name="请选择" id="zonename" class="c-s">
                                    <option value="">啦</option>
                                    <option value="">啦2</option>
                                    <option value="">啦3</option>
                                </select>
                            </div>
                            <div class="margintop">
                                <p class="areaname">网点名称：</p>
                                <select name="请选择" id="areaname" class="c-s">
                                    <option value="">啦</option>
                                    <option value="">啦2</option>
                                    <option value="">啦3</option>
                                </select>
                            </div>
                        </div>
                        <h4 class="labels">签到信息</h4>
                        <div class="c-c">
                            <div class="margintop">
                                <p class="areaname">到场时间：</p>
                                <input type="text" class="input-border1">
                            </div>
                            <div class="margintop">
                                <p class="areaname">现场设备数：</p>
                                <input type="text" class="input-border1">
                            </div>
                            <div class="margintop">
                                <p class="areaname">巡检反馈：</p>
                                <textarea name="" id="" cols="30" rows="10" style="width:60%;height:100px;"></textarea>
                            </div>
                        </div>
                        <h4 class="labels">图片上传</h4>
                        <p class="p-tips">TIPS：请在实施前/后各拍一张区域全局图！</p>
                        <div class="c-c"style="width:80%;margin:0 auto;">
                            <div class="" >
                                <input type="file" name="file" class="input-border1 add-img" value="+" multiple="multiple" onchange="UpdateFile(this)" />
                                <!-- <input class="input-border1 add-img" value="+" type="button"> -->
                            </div>
                        </div>
                    </div>
                    <div class="footer">
                        Powered by 乐摩吧<br>© 2017
                    </div>
                </div>
                
                
            </div>
        </body>
        </html>
        
        <script src="js/weui.js"></script>
        <script src="js/jquery-1.7.1.min.js"></script>
        <script>
            
            var arr = [];
            function selectEventApps(obj) {
                var selEventApp = $(obj).val();
                arr.push(selEventApp);
                var k = obj.parentNode.parentNode.children;
                if (selEventApp == '无') {
                    for (var i = 0; i < arr.length; i++) {
                        for (var j = 0; j < k.length - 1; j++)
                            if (k[j].innerText == arr[i]) {
                                k[j].children[0].checked = false;
                                break;
                            }
                    }
                    arr = [];
                    obj.checked = true;
                    arr.push(selEventApp);
                } else {
                    var f = -1; var index = 0; var flag = true;
                    for (var i = 0; i < arr.length - 1; i++) {
                        if (arr[i] == '无') {
                            document.getElementById("checkeventapp_000").checked = false;
                            f = i;
                            break;
                        } else if (selEventApp == arr[i]) {
                            f = -2;
                            for (var j = 0; j < k.length - 1; j++)
                                if (k[j].innerText == arr[i]) {
                                    flag = k[j].children[0].checked;
                                    index = i;
                                    break;
                                }
                            break;
                        }
                    }
                    if (f != -1 && f != -2) {
                        arr = [];
                        arr.push(selEventApp);
                        obj.checked = true;
                        //arr.splice(f, 1);
                    } else if (f == -2) {
                        arr.pop();
                        if (flag == false) {
                            if (arr.length > 1) {
                                arr.splice(index, 1);
                            }
                            else {
                                obj.checked = true;
                            }
                        }
                    }
        
                }
                console.log(arr);
                var hiden = $("#hidEventApp").val(arr.toString());
            }
            var arr2 = [];
            function selectEventAppsc(obj) {
                var selEventApp = $(obj).val();
                arr2.push(selEventApp);
                var k = obj.parentNode.parentNode.children;
                if (selEventApp == '无') {
                    for (var i = 0; i < arr2.length; i++) {
                        for (var j = 0; j < k.length - 1;j++)
                            if (k[j].innerText == arr2[i]) {
                                k[j].children[0].checked = false;
                                break;
                            }
                    }
                    arr2 = [];
                    obj.checked = true;
                    arr2.push(selEventApp);
                } else {
                    var f = -1;var index = 0;var flag = true;
                    for (var i = 0; i < arr2.length-1; i++) {
                        if (arr2[i] == '无') {
                            document.getElementById("checkeventapp_00").checked = false;
                            f = i;
                            break;
                        } else if (selEventApp == arr2[i]) {
                            f = -2;
                            for (var j = 0; j < k.length - 1;j++)
                                if (k[j].innerText == arr2[i]) {
                                    flag = k[j].children[0].checked;
                                    index = i;
                                    break;
                                }
                            break;
                        }
                    }
                    if (f != -1&&f!=-2) {
                        arr2 = [];
                        arr2.push(selEventApp);
                        obj.checked = true;
                        //arr2.splice(f, 1);
                    } else if(f == -2){
                        arr2.pop();
                        if (flag == false){
                            if (arr2.length>1){
                                arr2.splice(index, 1);
                            }
                            else {
                                obj.checked = true;
                            }
                        }
                    }
                    
                }
                var hiden = $("#hidEventApp2").val(arr2.toString());
                //var l = obj.parentNode.parentNode.children.length;
                //var k = obj.parentNode.parentNode.children;
                //for (var i = 0; i < l - 1; i++) {
                //    if (k[i].children[0].checked && k[i].children[0].id != obj.id) {
                //        k[i].children[0].checked = false;
                //    }
                //}
            }
            
            function postData() {
                if ($.trim($("#txtUserName").val()).length == 0) {
                    Msg.show("姓名不能为空", 1);
                    return;
                }
                if ($.trim($("#txtPhone").val()).length == 0) {
                    Msg.show("联系电话不少于5个字", 1);
                    return;
                }
                if ($.trim($("#hdNO").val()).length == 0) {
                    Msg.show("请输入设备编号5个字", 1);
                    return;
                }
                if ($.trim($("#txtEventContent").val()).length < 5) {
                    Msg.show("故障描述不少于5个字", 1);
                    return;
                }
                if ($.trim($("#hidEventApp").val()).length == 0) {
                    Msg.show("设备异常不能为空", 1);
                    return;
                }
                if ($.trim($("#hidEventApp2").val()).length == 0) {
                    Msg.show("运营异常不能为空", 1);
                    return;
                }
                
                $("#btnSubmit").attr('disabled', 'disabled');
                //window.setTimeout("$('#btnSubmitRepair').removeAttr('disabled');", 15000);
        
                Msg.show("提交中...", 3);
                $("#btnSubmit").button('loading');
        
                $("#btnSubmit").attr('disabled', 'disabled');
                
                var data = { form_type: 2, name: $("#txtUserName").val(), phone: $("#txtPhone").val(), identity: $("#sltType").val(), province: $("#hprovince").val(), city: $("#hcity").val(), area: $("#txtArea").val(), device_id: $("#hdNO").val(), fault_type: $("#hidEventApp").val(), parts_replace: $("#hidEventApp2").val(), desc: $("#txtEventContent").val(), path: $("#txtEventFiles").val() };
                $.ajax({
                    type: "post",
                    url: '/repair/PostRepairForm',
                    data: data,
                    // cache: false,
                    //async: false,
                    dataType: "json",
                    success: function (obj) {
                        if (obj.status == 'success' && obj.message == '提交成功！') {
                            
                            //$(".ui-ios-overlay").remove();
                            $("#btnSubmit").text('确认提交');
                            Msg.show("提交成功!", 2);
                            window.location.href = "/?pageid=2";
                        } else {
                            Msg.show("提交失败", 1);
                        }
                    },
                    error: function (data, text) {
        
                        console.log(data);
                    }
                });
            }
            var UpdateFile = function (el) {
                if ($("#txtUserName").val() == "" || $("#txtArea").val() == "") {
                    Msg.show("信息填写不全", 1);
                }else{
                    if (el.files.length > 0) {// && el.files.length <= 10
                        for (var fl = 0; fl < el.files.length; fl++) {
                            if (el.files[fl].size > 5 * 1024 * 1024) {
                                Msg.show("上传的图片过大,请上传小于5M的照片!", 1);
                                return;
                            }
                        }
                        //$.showPreloader('上传中...');
                        var form = new FormData();
                        for (var i = 0; i < el.files.length; i++) {
                            form.append("file_" + i, el.files[i]);
                        }
                        //var fileObj = file; // js 获取文件对象
                        Msg.show("上传中...", 3);
                        var UploadUrl = '/Upload/UpLoadFile';          // 接收上传文件的后台地址 
                        //form.append("file", $(el).data("index"));
                        var xhr = new XMLHttpRequest();
                        xhr.open("post", UploadUrl, true);
                        xhr.onload = function (e) {
                            var FileData = JSON.parse(e.target.response);
                            Msg.hide();
                            if (FileData.status == '1') {
                                Msg.show();
                                $("#txtEventFiles").val(FileData.path);
                            }
                        };
                        xhr.send(form);
        
                    }
                    else {
                        $.alert("必须大于一张图片");
                    }
                }
            }
        </script>
        